<?php

namespace app\models;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "type".
 *
 * @property integer $typeid
 * @property string $name
 */
class Type extends \yii\db\ActiveRecord
{
    const TEN = 1;
    const HUNDRED = 2;
    public static function dropdown($column, $value = null)
    {
        $dropDownList = [
            'type'=>ArrayHelper::map(self::find()->all(),'typeid','name'),
        ];
        if ($value !== null)
            return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false;
        else
            return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false;
    }
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'type';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            ['name','unique'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'typeid' => 'id',
            'name' => '名称',
        ];
    }


}
